int indexLine(int checker, int queenTotal){
    return (checker / queenTotal);
}

int indexRow(int checker, int queenTotal){
    return (checker % queenTotal);
}

bool isLine(int checkerQueen, int checker, int queenTotal){
    return (indexLine(checkerQueen, queenTotal) == indexLine(checker, queenTotal));
}

bool isRow(int checkerQueen, int checker, int queenTotal){
    return (indexRow(checkerQueen, queenTotal) == indexRow(checker, queenTotal));
}

bool isSlash(int checkerQueen, int checker, int queenTotal){
    int rowQueen = indexRow(checkerQueen, queenTotal);
    int lineQueen = indexLine(checkerQueen, queenTotal);
    int row = indexRow(checker, queenTotal);
    int line = indexLine(checker, queenTotal);
    return ((rowQueen + lineQueen) == (row + line));
}

bool isBackslash(int checkerQueen, int checker, int queenTotal){
    int rowQueen = indexRow(checkerQueen, queenTotal);
    int lineQueen = indexLine(checkerQueen, queenTotal);
    int row = indexRow(checker, queenTotal);
    int line = indexLine(checker, queenTotal);
    return ((line - lineQueen) == (row - rowQueen));
}

bool isPlaceable(int *checkerQueens, int queenPlaced, int queenTotal, int checker){
    for(int i = 0; i < queenPlaced; ++i){
        int checkerQueen = checkerQueens[i];
        if(isLine(checkerQueen, checker, queenTotal)) return false;
        if(isRow(checkerQueen, checker, queenTotal)) return false;
        if(isSlash(checkerQueen, checker, queenTotal)) return false;
        if(isBackslash(checkerQueen, checker, queenTotal)) return false;
    }
    return true;
}

int nQueen1(int queenTotal){
    int result = 0;
    if(queenTotal < 1){
        return result;
    }
    int *checkerQueens = new int[queenTotal];
    int checker = 0;
    int queenPlaced = 0;
    while(queenPlaced > 0 || checker < queenTotal){
        if(queenPlaced != indexLine(checker, queenTotal)){
            checker = checkerQueens[--queenPlaced] + 1;
        }else if(isPlaceable(checkerQueens, queenPlaced, queenTotal, checker)){
            checkerQueens[queenPlaced++] = checker;
            if(queenPlaced == queenTotal){
                ++result;
                checker = checkerQueens[--queenPlaced] + 1;
            }else{
                checker = queenPlaced * queenTotal;
            }
        }else{
            checker++;
        }
    }
    delete[] checkerQueens;
    return result;
}
